package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.PrizeDrawActivityAward;
import com.sc.nft.entity.dto.RaffleRouletteDTO;
import com.sc.nft.mapper.PrizeDrawActivityAwardMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 抽奖活动的奖品(PrizeDrawActivityAward)表Dao层
 *
 * @author wwc
 * @since 2023-08-22 14:07:07
 */
@Slf4j
@Repository
public class PrizeDrawActivityAwardDao extends ServiceImpl<PrizeDrawActivityAwardMapper, PrizeDrawActivityAward> {

    public List<PrizeDrawActivityAward> getByPrizeDrawActivityId(Long id) {
        return this.lambdaQuery().eq(PrizeDrawActivityAward::getPrizeDrawActivityId, id).list();
    }

    public List<PrizeDrawActivityAward> raffleRoulette(RaffleRouletteDTO raffleRouletteDTO) {
        LambdaQueryWrapper<PrizeDrawActivityAward> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(PrizeDrawActivityAward::getPrizeDrawActivityId, raffleRouletteDTO.getId());
        lambdaQueryWrapper.eq(PrizeDrawActivityAward::getDaoId, raffleRouletteDTO.getDaoId());
        return list(lambdaQueryWrapper);
    }

    public void updateResidue(Long prizeId) {
        this.lambdaUpdate().setSql("residue = residue - 1").eq(PrizeDrawActivityAward::getId, prizeId).update();
    }

}
